package cn.team11.smarteye.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import cn.team11.sds.dayi.R;

/**
 * Created by Yang on 2017/10/28.
 * 自定义toolbar
 */

public class CustomToolbar extends FrameLayout{

    TextView mleftTitle;
    TextView mMidTitle;
    TextView mRightTitle;

    public CustomToolbar(Context context) {
        this(context, null);
    }

    public CustomToolbar(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View view = LayoutInflater.from(context).inflate(R.layout.default_toolbar_layout, null);
        addView(view);

        mleftTitle = (TextView) view.findViewById(R.id.toolbar_left_title);
        mMidTitle = (TextView) view.findViewById(R.id.toolbar_middle_title);
        mRightTitle = (TextView) view.findViewById(R.id.toolbar_right_title);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
    }

    /**
     * 设置返回action
     * */
    public void setBackAction(OnClickListener clickListener){
       if (clickListener != null)
           mleftTitle.setOnClickListener(clickListener);
    }

    /**设置title的名称*/
    public void setMidTitle(String name){
        mMidTitle.setText(name);
    }

    /**
     * 设置右边action
     * */
    public void setRightAction(OnClickListener clickListener){
        if (clickListener != null)
            mRightTitle.setOnClickListener(clickListener);
    }

    /**
     * 设置右边action是否可用
     * */
    public void setRightEnable(boolean enable){
        mRightTitle.setEnabled(enable);
    }


    /**
     * 设置右侧action是否可见
     * */
    public void setRightVisibility(int visibility){
        mRightTitle.setVisibility(visibility);
    }

    public void setLeftVisibility(int visibility){
        mleftTitle.setVisibility(visibility);
    }


    /**
     * 设置右侧action图标
     * */
    public void setRightIcon(Drawable drawable){
        mRightTitle.setCompoundDrawables(null, null, drawable, null);
    }

    /**
     * 设置右侧action名称
     * */
    public void setRightTitle(String name){
        mRightTitle.setText(name);
    }

    public void setLeftTitle(String name){
        mleftTitle.setText(name);
    }
    public void setLeftIcon(Drawable drawable){
        mleftTitle.setCompoundDrawables(drawable, null, null, null);
    }
}
